summaryrefslogtreecommitdiff
path: root/src/pages/posts/[...slug].astro
blob: b66d911d122e312c88524882bd9f52e84b526c75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
---
import { render } from "astro:content";
import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
import { getAllPosts, getPostNavigation } from "@/data/post";
import PostLayout from "@/layouts/BlogPost.astro";

// if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr
export const getStaticPaths = (async () => {
	const blogEntries = await getAllPosts(true); // Include archived posts for direct access
	return blogEntries.map((post) => {
		const { prevPost, nextPost } = getPostNavigation(blogEntries, post);
		return {
			params: { slug: post.id },
			props: { post, prevPost, nextPost },
		};
	});
}) satisfies GetStaticPaths;

type Props = InferGetStaticPropsType<typeof getStaticPaths>;

const { post, prevPost, nextPost } = Astro.props;
const { Content } = await render(post);
---

<PostLayout post={post} prevPost={prevPost} nextPost={nextPost}>
	<Content />
</PostLayout>